set scheme s2color

use "$project_path/data/4_regdata/dynamics/regdata_dynamics", clear

// Computing effects
foreach v in diff_m1_chix_econ std_diff_m1_growth_gdpc_penn mstd_diff_m1_inflation_imf mstd_diff_m1_unemployment_ilo std_diff_m1_trade_wb std_diff_m1_hdi std_diff_m1_lifeexp_index std_diff_m1_educ_index std_diff_m1_income_index std_diff_m1_democracy_index diff_m1_general_chix {
	
	local v_short = subinstr("`v'", "mstd_", "", .)
	local v_short = subinstr("`v_short'", "std_", "", .)
	local v_short = subinstr("`v_short'", "diff_m1_", "", .)

	matrix res_mat_`v_short' = J(7, 3, .)
	matrix coln res_mat_`v_short' = tau ci_low ci_high
	local laglabels = "Placebo 0 1 2 3 4 5"
	matrix rown res_mat_`v_short' = `laglabels'

	local row = 0
	foreach k in -2 0 1 2 3 4 5 {
		local row = `row'+1
		rdrobust `v' runvar if relative_year==`k', level(90)
		matrix res_mat_`v_short'[`row',1] = e(tau_cl)
		matrix res_mat_`v_short'[`row',2] = e(ci_l_rb)
		matrix res_mat_`v_short'[`row',3] = e(ci_r_rb)
	}

}

// Figure 6(a)
coefplot ///
(matrix(res_mat_chix_econ[.,1]), ci((res_mat_chix_econ[.,2] res_mat_chix_econ[.,3])) offset(-0.3) color(midblue) ciopts(lwidth(*2) lcolor(midblue) )) ///
(matrix(res_mat_growth_gdpc_penn[.,1]), ci((res_mat_growth_gdpc_penn[.,2] res_mat_growth_gdpc_penn[.,3])) offset(-0.15) color(dkgreen) ciopts(lwidth(*2) lcolor(dkgreen)) msymbol(O) mfcolor(white)) ///
(matrix(res_mat_inflation_imf[.,1]), ci((res_mat_inflation_imf[.,2] res_mat_inflation_imf[.,3])) offset(0) color(midgreen) ciopts(lwidth(*2) lcolor(midgreen)) msymbol(O) mfcolor(white)) ///
(matrix(res_mat_unemployment_ilo[.,1]), ci((res_mat_unemployment_ilo[.,2] res_mat_unemployment_ilo[.,3])) offset(0.15) color(sand) ciopts(lwidth(*2) lcolor(sand)) msymbol(O) mfcolor(white)) ///
(matrix(res_mat_trade_wb[.,1]), ci((res_mat_trade_wb[.,2] res_mat_trade_wb[.,3])) offset(0.3) color(erose) ciopts(lwidth(*2) lcolor(erose)) msymbol(O) mfcolor(white)) ///
, yline(0) xline(1.5, lwidth(thick) lcolor(black%30)) vertical title("Economic performance", size(vlarge)) xlabel(,labsize(large)) ylabel(-0.4(0.4)0.8,labsize(large)) xtitle("Years after the election", size(large)) graphregion(color(white)) ytitle("Standard deviations", size(large)) legend(label(2 "Econ. perf.") label(4 "GDP growth") label(6 "(Minus) Inflation") label(8 "(Minus) Unemp.") label(10 "Trade") size(large) rows(2) region(col(white)))
graph export "$project_path/output/figures/Figure_6a.pdf", as(pdf) name("Graph") replace

// Figure 6(b)
coefplot ///
(matrix(res_mat_hdi[.,1]), ci((res_mat_hdi[.,2] res_mat_hdi[.,3])) offset(-0.3) color(midblue) ciopts(lwidth(*2) lcolor(midblue) )) ///
(matrix(res_mat_income_index[.,1]), ci((res_mat_income_index[.,2] res_mat_income_index[.,3])) offset(-0.15) color(dkgreen) ciopts(lwidth(*2) lcolor(dkgreen) ) msymbol(O) mfcolor(white)) ///
(matrix(res_mat_lifeexp_index[.,1]), ci((res_mat_lifeexp_index[.,2] res_mat_lifeexp_index[.,3])) offset(0) color(midgreen) ciopts(lwidth(*2) lcolor(midgreen) ) msymbol(O) mfcolor(white)) ///
(matrix(res_mat_educ_index[.,1]), ci((res_mat_educ_index[.,2] res_mat_educ_index[.,3])) offset(0.15) color(sand) ciopts(lwidth(*2) lcolor(sand) ) msymbol(O) mfcolor(white)) ///
, yline(0) xline(1.5, lwidth(thick) lcolor(black%30)) vertical title("Human Development Index", size(vlarge)) xlabel(,labsize(large)) ylabel(-0.4(0.4)1.2,labsize(large)) xtitle("Years after the election", size(large)) graphregion(color(white)) ytitle("Standard deviations", size(large)) legend(label(2 "HDI") label(4 "Income component") label(6 "Life expectancy component") label(8 "Education component") size(large) rows(2) region(col(white)))
graph export "$project_path/output/figures/Figure_6b.pdf", as(pdf) name("Graph") replace

// Figure 6(c)
coefplot (matrix(res_mat_democracy_index[.,1]), ci((res_mat_democracy_index[.,2] res_mat_democracy_index[.,3])) offset(0) color(midblue) ciopts(lwidth(*3) lcolor(midblue) )) , yline(0) xline(1.5, lwidth(thick) lcolor(black%30)) vertical title("Democracy", size(vlarge)) xlabel(,labsize(large)) ylabel(-0.2(0.2)0.8,labsize(large)) xtitle("Years after the election", size(large)) graphregion(color(white)) legend(off) ytitle("Standard deviations", size(large))
graph export "$project_path/output/figures/Figure_6c.pdf", as(pdf) name("Graph") replace


// Figure 6(d)
coefplot (matrix(res_mat_general_chix[.,1]), ci((res_mat_general_chix[.,2] res_mat_general_chix[.,3])) offset(0) color(midblue) ciopts(lwidth(*3) lcolor(midblue) )) , yline(0) xline(1.5, lwidth(thick) lcolor(black%30)) vertical title("General index", size(vlarge)) xlabel(,labsize(large)) ylabel(-0.2(0.2)0.8,labsize(large)) xtitle("Years after the election", size(large)) graphregion(color(white)) legend(off) ytitle("Standard deviations", size(large))
graph export "$project_path/output/figures/Figure_6d.pdf", as(pdf) name("Graph") replace
